Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make mx.compile work on Windows #1697

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

zcbenz
Copy link
Contributor

@zcbenz zcbenz commented Dec 13, 2024

Refs #1513.

This PR adds code to invoke MSVC on Windows. Most of the new code are about getting the paths information of Visual Studio.

Comment on lines 196 to 219
#ifdef _MSC_VER
const VisualStudioInfo& info = GetVisualStudioInfo();
std::string libpaths;
for (const std::string& lib : info.libpaths) {
libpaths += fmt::format(" /libpath:\"{0}\"", lib);
}
std::string build_command = fmt::format(
"\""
"cd /D \"{0}\" && "
"\"{1}\" /LD /EHsc /MD /Ox /nologo /std:c++17 \"{2}\" "
"/link /out:\"{3}\" {4} >nul"
"\"",
std::filesystem::temp_directory_path().string(),
info.cl_exe,
source_file_name.str(),
shared_lib_name.str(),
libpaths);
#else
std::string build_command = fmt::format(
"g++ -std=c++17 -O3 -Wall -fPIC -shared '{0}' -o '{1}'",
source_file_path,
shared_lib_path);
#endif
auto return_code = system(build_command.c_str());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to encapsulated the compiler into it's own class to contain the if-defs and make this more maintainable / extensible.

Something like:

static std::string JitCompiler::build_command(
  const std::string& source_file_path, const std::string& shared_lib_name)

// And we could include any special source code headers needed in the class as well. 
static std::string JitCompiler::get_header()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then again.. we only have three compilers (g++, clang, msvc) right now.. so I'm also ok to wait and see if we need to generalize this again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is good timing to move the code to a separate file, I have updated the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants